<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@taglib uri="uiTags" prefix="ui"%>

<script type="text/javascript">
	var roleRightGrant ={
			saveRights:function(){
				var checkedNodes = $('#role_button_grant_treegridid').treegrid('getCheckedNodes');
				var checkedMenuStr = '';
				var checkedButtonStr = '';
				$.each(checkedNodes,function(i,item){
					checkedMenuStr = checkedMenuStr + item.id+",";
				});
				$('input[name="_treegrid_button_selected"]:checked').each(function(i,item){ 
					checkedButtonStr = checkedButtonStr + $(this).val()+","; 
				});
				var param = new Object();
				param.checkedMenuStr = checkedMenuStr;
				param.checkedButtonStr = checkedButtonStr;
				param.roleid= '${roleid}';
				ajaxRequest("user/saveRights",param);
				showWarnAlert("保存成功!");
				closeCurrentTab();
			}	
	}
	$(function(){
		$('#role_button_grant_treegridid').treegrid({
		    data:eval("(" + '${funcdata}' + ")"),
		    idField:'id',
		    treeField:'text',
		    checkbox:true,
		    onlyLeafCheck:true,
		    nowrap:false,//文本换行
		    //点击之后更新这行
		    onCheckNode:function(node,check){
		    	if(!check){
					$.each(node.buttons,function(i,item){
						item.checked=false;
					});	
		    	}
		    	$('#role_button_grant_treegridid').treegrid('refresh',node.id);
			},
		    columns:[[
				{title:'菜单',field:'text',width:'30%'},
				{field:'buttons',title:'按钮',width:'65%',
					formatter:function(value,row,index){
						if(value == null){
							return null;
						}
						var disabeledStr ="";
						var returnValue = '';
						if(!row.checked){
							disabeledStr = "disabled='disabled'";
						}
						$.each(value,function(i,item){
							var checkedStr='';
							if(item.checked){
								checkedStr = "checked='checked'";
							}
							returnValue=returnValue+"<div style='width:25%;float:left'>"  + item.text+" <input name='_treegrid_button_selected' type ='checkbox' value= '"+item.value+"' "+disabeledStr+" "+checkedStr+ "></div>";
						});	
						return returnValue;
					}
				}
		    ]]
		});
	
});
</script>
<ui:body>
	<div class="easyui-layout" style="width: 100%;height: 100%;" fit="true">
		<div data-options="region:'north',border:false" style="width: 100%;height: 95%;">
			<table id="role_button_grant_treegridid"></table>
		</div>
		<div data-options="region:'south',border:true"
			style="text-align: right;overflow: hidden;">
			<ui:button onclick="roleRightGrant.saveRights()" icon="icon-ok"
				value="提交" />
			<ui:button onclick="closeCurrentTab()" icon="icon-ok" value="关闭" />
		</div>
	</div>
</ui:body>
